package com.hulk.dryad.manage.provider.transaction;

import com.hulk.dryad.manage.framework.storage.Storage;
import com.hulk.dryad.persistence.entity.SysFileModel;

import com.hulk.dryad.manage.provider.service.SysFileService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author  lqx
 * @date 2020/10/20
 * 2020/10/13
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class S3FsTransaction {

    private final SysFileService sysFileService;
	private final Storage storageTemplate;

	/**
	 * 删除文件
	 * @param id
	 * @return
	 */
	@SneakyThrows
	@Transactional(rollbackFor = Exception.class)
	public Boolean deleteFile(Long id) {
		SysFileModel file = sysFileService.getById(id);
	    boolean flag = sysFileService.removeById(id);
		storageTemplate.delete( file.getFileName() , file.getFileDir(),  file.getBucketName());
		return flag;
	}


}
